Conditions | 1 |
Paths | 1 |
Total Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // Directives |
||
18 | Directives.prototype.defineConfirm = function () { |
||
19 | const _this = this |
||
20 | const DirectiveDefinition = {} |
||
21 | |||
22 | const getConfirmMessage = function(binding) { |
||
23 | if (binding.value && binding.value.message) { |
||
24 | return binding.value.message |
||
25 | } |
||
26 | return typeof binding.value === 'string' ? binding.value : null |
||
27 | } |
||
28 | |||
29 | const getCatchCallback = function(binding) { |
||
30 | if (binding.value && binding.value.cancel) { |
||
31 | return binding.value.cancel |
||
32 | } |
||
33 | return noop |
||
34 | } |
||
35 | |||
36 | const getThenCallback = function(binding, el){ |
||
37 | if (binding.value && binding.value.ok) { |
||
38 | return binding.value.ok |
||
39 | } else { |
||
40 | return () => { |
||
41 | // Unbind to allow original event |
||
42 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
43 | // Trigger original event |
||
44 | clickNode(el) |
||
45 | // Re-bind listener |
||
46 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | const clickHandler = function (event, el, binding) { |
||
52 | event.preventDefault() |
||
53 | event.stopImmediatePropagation() |
||
54 | |||
55 | let confirmMessage = getConfirmMessage(binding) |
||
56 | let thenCallback = getThenCallback(binding, el) |
||
57 | let catchCallback = getCatchCallback(binding) |
||
58 | |||
59 | _this.Vue.dialog |
||
60 | .confirm(confirmMessage) |
||
61 | .then(thenCallback) |
||
62 | .catch(catchCallback) |
||
63 | } |
||
64 | |||
65 | |||
66 | DirectiveDefinition.bind = (el, binding) => { |
||
67 | if (el.VuejsDialog === undefined) { |
||
68 | el.VuejsDialog = {} |
||
69 | } |
||
70 | |||
71 | el.VuejsDialog.clickHandler = function clickEventHandler(event) { |
||
72 | clickHandler(event, el, binding) |
||
73 | } |
||
74 | |||
75 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
76 | } |
||
77 | |||
78 | DirectiveDefinition.unbind = (el) => { |
||
79 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
80 | } |
||
81 | |||
82 | return DirectiveDefinition |
||
83 | } |
||
84 | |||
90 |